package com.zhz.common.tool.mybatisplus.base.core.enums;

import lombok.AllArgsConstructor;

@AllArgsConstructor
public enum ResultCode implements IEnum<Integer>, EnumValueResolver<ResultCode,Integer> {
    OK(true, 200, "请求/操作成功"),
    FAIL(false, 500, "请求成功但是服务异常"),
    UNAUTHORIZED(false, 401, "未登录或token已经失效"),
    FORBIDDEN(false, 403, "没有权限"),
    SERVER_ERROR(false, 500, "服务器异常"),
    REQUEST_ERROR(false, 400, "请求异常");
    //操作是否成功
    private final boolean success;
    private final Integer code;
    private final String message;

    public static String getDescByCode(Integer code) {
        String desc = "";
        ResultCode[] var2 = values();
        int var3 = var2.length;

        for (int var4 = 0; var4 < var3; ++var4) {
            ResultCode codeEnum = var2[var4];
            if (codeEnum.getCode().equals(code)) {
                desc = codeEnum.getMessage();
                break;
            }
        }

        return desc;
    }

    public static ResultCode getByCode(Integer code) {
        ResultCode resultCode = null;
        ResultCode[] var2 = values();
        int var3 = var2.length;

        for (int var4 = 0; var4 < var3; ++var4) {
            ResultCode codeEnum = var2[var4];
            if (codeEnum.getCode().equals(code)) {
                resultCode = codeEnum;
                break;
            }
        }

        return resultCode;
    }

    /**
     * 是否成功
     */
    public Boolean getSuccess() {
        return this.success;
    }

    /**
     * 获取编码
     *
     * @return
     */
    @Override
    public Integer getCode() {
        return this.code;
    }

    /**
     * 获取描述
     *
     * @return
     */
    @Override
    public String getMessage() {
        return this.message;
    }
}